package practical_projects.games.submarine_war;

import javax.swing.*;
import java.awt.Graphics;
import java.util.Random;

public abstract class Weapon {  // 抽象类，武器装备类，战舰、潜艇、炸弹、水雷的父类
    protected int width;    // 宽
    protected int height;   // 高
    protected int x;        // x坐标
    protected int y;        // y坐标
    protected int speed;    // 移动速度
    private boolean status = true;  // 是否活着

    public Weapon(int width, int height, int x, int y, int speed) {
        this.width = width;
        this.height = height;
        this.x = x;
        this.y = y;
        this.speed = speed;
    }

    public Weapon(int width, int height) {
        this.width = width;
        this.height = height;
        x = -width;
        Random ran = new Random();
        y = ran.nextInt(World.HEIGHT - World.seaLevel - height + 1) + World.seaLevel;
        speed = ran.nextInt(3) + 1;
    }

    public abstract void move();   // 移动方法，抽象方法

    public abstract ImageIcon getImage();   // 获取图片

    protected boolean isLive() {   // 是否活着
        return status;
    }

    protected void setStatus(boolean status) {
        this.status = status;
    }

    protected void paintImage(Graphics g) {
        if(this.isLive())
            this.getImage().paintIcon(null, g, this.x, this.y);
    }
}
